<?php
@$listType = $_REQUEST['listType'];

include 'header.php';

@$pageNum = $_REQUEST['pageNum'];

$pageNum = pageNum($pageNum);
$sql = 'select goods.id as gId,type.id as tId,imgUrl,goods.name as gName,type.name as tName,
							stockPrice,sellPrice,sellStatus,basicStatus,stock,typeId from goods 
							join type on goods.typeId=type.id order by goods.id asc';
$pageSize = 10;
@$goods = dbSelectPage($sql,$pageNum,$pageSize);
@$count = dbSelectAll($sql);
$num = ceil(count($count)/$pageSize);
?>
		<div class='container'>
   			<div class='row'>
   				<div class='col-xs-2'>
   					<?php if($listType == 'price'||$listType == 'status'||$listType == 'stock'){?>
	   					<a href='index.php' class='btn btn-default btn-block'>返回首页</a>
   					<?php }else{?>
	   					<a href='index.php' class='btn btn-default btn-block'>返回首页</a>
	   					<a href='addGoodsType.php?addType=goods' class='btn btn-default btn-block'>添加商品</a>
	   					<a href='typeList.php' class='btn btn-default btn-block'>类型列表</a>
	   					<a href='addGoodsType.php?addType=type' class='btn btn-default btn-block'>添加商品类型</a>
	   				<?php }?>
   				</div>
   				<div class='col-xs-10'>
   					<div class='panel panel-primary'>
   						<div class='panel-heading'>
   							<?php if($listType == 'stock'){?>
   								<div class='panel-title'>所有商品库存列表</div>
   							<?php }else if($listType == 'price'){?>
   								<div class='panel-title'>所有商品价格列表</div>
   							<?php }else if($listType == 'status'){?>
   								<div class='panel-title'>所有商品状态列表</div>
   							<?php }else{?>
   								<div class='panel-title'>所有商品列表</div>
   							<?php }?>
   						</div>
   						<table class='goodsTable table table-bordered text-center'>
   							<tr>
   								<th class='text-center'>图片</th>
   								<th class='text-center'>名称</th>
   								<th class='text-center'>采购价格</th>
   								<th class='text-center'>销售价格</th>
   								<th class='text-center'>销售状态</th>
   								<th class='text-center'>基本状态</th>
   								<?php if($listType == 'stock'){?>
   									<th class='text-center'>库存量</th>
   								<?php }?>
   								<th class='text-center'>商品类型</th>
   								<th class='text-center'>编辑</th>
   							</tr>
   							<?php foreach($goods as $good){?>
	   							<tr id='goodsTr<?php echo $good['gId'];?>'>
	   								<td><img src="img/<?php echo $good['imgUrl'];?>" class='goodsImg' /></td>
	   								<td><?php echo $good['gName'];?></td>
	   								<td><?php echo $good['stockPrice'];?></td>
	   								<td><?php echo $good['sellPrice'];?></td>
	   								<td><?php echo $good['sellStatus'];?></td>
	   								<td><?php echo $good['basicStatus'];?></td>
	   								<?php if($listType == 'stock'){?>
	   									<td><?php echo $good['stock'];?></td>
	   								<?php }?>
	   								<td><?php echo $good['tName'];?></td>
	   								<?php if($listType == 'price'){?>
	   									<td>
		   									<a href="updatePrice.php?id=<?php echo  $good['gId'];?>&&priceType=stockPrice">采购价格</a>
		   									<a href="updatePrice.php?id=<?php echo  $good['gId'];?>&&priceType=sellPrice">销售价格</a>
		   								</td>
	   								<?php }else if($listType == 'status'){?>
	   									<td>
		   									<a href='updateStatus.php?id=<?php echo $good['gId'];?>&&statusType=sellStatus'>销售状态</a>
		   									<a href='updateStatus.php?id=<?php echo $good['gId'];?>&&statusType=basicStatus'>基本状态</a>
		   								</td>
	   								<?php }else if($listType == 'stock'){?>
	   									<td>
		   									<a href='updateStock.php?id=<?php echo $good['gId'];?>&&stockType=inStock'>进货</a>
		   									<a href='updateStock.php?id=<?php echo $good['gId'];?>&&stockType=outStock'>出货</a>
		   								</td>
	   								<?php }else{?>
		   								<td>
		   									<a href='updateGoodsType.php?goodsId=<?php echo $good['gId'];?>&&updateType=goods'>编辑</a>
		   									<a href='#' id='delGoods<?php echo $good['gId'];?>'>删除</a>
		   								</td>
	   								<?php }?>
	   						<?php }?>
   						</table>
   						<div class='panel-body'>
   							<?php include 'pageTemp.php';?>
   						</div>
   					</div>
   				</div>
   			</div>
   		</div>
   	</body>
</html>